Component({
  data: {
    register: false,
    Height: null,
    Width: null
  },
  properties: {
    register: {
      type: Boolean,
      value: false
    },
    Height: {
      type: Number,
      value: 0
    },
    Width: {
      type: Number,
      value: 0
    }
  },
  observers: {
    register(n, l) {
      // console.log(n);
    }
  },

  attached() {
    //进入时执行
  },
  methods: {
    getUserProfile(e) {
      this.HandleUserlogin()
      wx.getUserProfile({
        lang: 'zh_CN',
        desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
        success(res){
          console.log(res);
          let sessionkey = wx.$cache.get('sessionkey')
          let pardata = {
            sessionKey: sessionkey,
            iv: res.iv,
            encryptedData: res.encryptedData
          }
          wx.showLoading({
            title: '登录中..',
          })
          wx.$http.post(wx.$get.getLogin, pardata).then(res => {
            console.log(res);
            wx.hideLoading()
            wx.$cache.set('userInfo', res.data);
            // 关闭授权弹窗
            let pageArr = getCurrentPages();
            let thisPage = pageArr[pageArr.length - 1];
            thisPage.setData({
              register: false,
            });
            thisPage.onShow()
          })
        }
      })
    },

    HandleUserlogin(){
        console.log('执行没');
        wx.getSetting({
          lang: 'zh_CN',
          success: res => {
            if (res.authSetting['scope.userInfo']) {
              wx.login({
                success: code => {
                  let data = {
                    code: code.code,
                  };
                  wx.$http.post(wx.$get.getOpenId, data).then(res => {
                    wx.$cache.set('sessionkey', res.data.data.sessionkey)
                  })
                }
              })
            }
          }
        })
    },


    closeModal() {
      this.setData({
        register: false
      })
    }
  },
});